<?
	include_once('header.php');
	include_once('sidebar.php');
	
	$plugin = $_GET['plugin'];
	$enable = $_GET['enable'];
	$disable = $_GET['disable'];
	$help = $_GET['help'];
	if($enable) {
		include_once(root_dir . "drizzo-addons/plugins/" . $enable);
		$enable_this = basename($enable,".php") . "_enable";
		if(function_exists($enable_this)) {
			$enable_this();
		}
	}
	if($disable) {
		include_once(root_dir . "drizzo-addons/plugins/" . $disable);
		$disable_this = basename($enable,".php") . "_disable";
		if(function_exists($disable_this)) {
			$disable_this();
		}
	}
	$update_options = drizzo_update_options();
?>

		<div id="main">
			
			<h2><? if($plugin) { $meta = drizzo_plugin_info($plugin); echo $meta['name'] . " Options"; } elseif($help) { $meta = drizzo_plugin_info($help); echo $meta['name'] . " Instructions"; } else { echo "Plugins"; }?></h2>

<?
	if($update_options == 2) {
		echo "\t\t\t\t<p class=\"save\">Options have been updated.</p>";
	} elseif($update_options == 1) {
		echo "\t\t\t\t<p class=\"alert\">Options could not be updated.</p>";
	}

	if(!$plugin && !$help) { // Default View
		if(!$enable && !$disable) {
			echo drizzo_plugins_table();
		} else {
			if($enable) {
				$enable = drizzo_db_wrap($enable);
				$enable_lookup = @mysql_query("SELECT `ID` FROM `$drizzo_options` WHERE `name`='$enable'");
				if(@mysql_num_rows($enable_lookup) > 0) {
					$enable_query = @mysql_query("UPDATE `$drizzo_options` SET `value`='enabled' WHERE `name`='$enable'");
				} else {
					$enable_query = @mysql_query("INSERT INTO `$drizzo_options` (`name`,`value`) VALUES ('$enable','enabled')");
				}
				$meta = drizzo_plugin_info(drizzo_db_unwrap($enable));
				extract($meta);
				if($enable_query) {
					echo "<p class=\"save\">$name has been enabled</p>";
				} else {
					echo "<p class=\"alert\">$name could not be enabled</p>";
				}
			} else {
				$disable = drizzo_db_wrap($disable);
				$disable_lookup = @mysql_query("SELECT `ID` FROM `$drizzo_options` WHERE `name`='$disable'");
				if(@mysql_num_rows($disable_lookup) > 0) {
					$disable_query = @mysql_query("UPDATE `$drizzo_options` SET `value`='disabled' WHERE `name`='$disable'");
				}
				$meta = drizzo_plugin_info(drizzo_db_unwrap($disable));
				extract($meta);
				if($disable_query) {
					echo "<p class=\"save\">$name has been disabled</p>";
				} else {
					echo "<p class=\"alert\">$name could not be disabled</p>";
				}
			}
			echo drizzo_plugins_table();
		}
	} elseif($plugin) { // End Default View; Display Options for Specified Plugin
		if(drizzo_plugin_options($plugin)) {
?>
			<form id="plugins" action="" method="post">
<?
		eval("?>" . drizzo_plugin_options($plugin));
		if(!$submit_term) {
			$submit_term = 'Save Options';
		}
?>
				<br class="clear" />
				<p class="center"><input type="submit" class="submit" id="plugins_submit" name="submit" value="<? echo $submit_term; ?>" /></p>
			</form>

<?
		} else {
?>
			<br class="clear" />
			<p>This plugin has no options</p>
<?
		}
	} elseif($help) {// End Display Options for Specified Plugin; Display Help for Specified Plugin
		if(drizzo_plugin_help($help)) {
			echo "<br class=\"clear\" />\n" . drizzo_plugin_help($help);
		} else {
?>
			<br class="clear" />
			<p>This plugin has no instructions</p>
<?
		}
	}
?>
			<br class="clear" />
			
		</div>
<?
	include_once('footer.php');
?>
